package com.example.cshaoshao.demo.entities;

import android.os.Handler;

import com.example.cshaoshao.demo.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cshaoshao on 2017/6/25.
 */

public class Data
{
    private CallBackParm callBackParm;
    private Handler handler=new Handler();
    public void setCallBackParm(CallBackParm callBackParm) {
        this.callBackParm = callBackParm;
    }

    private List<String> list=new ArrayList<>();
    public void getData()
    {
        try {
            for (int i = 'a'; i <'z' ; i++)
            {
                list.add(String.valueOf(i));
                LogUtil.d("Thread","3");

            }
//            if(callBackParm!=null)
//            {
//                LogUtil.d("Thread","4");
//                callBackParm.successful(list);
//                LogUtil.d("Thread","5");
//            }
            handler.post(new Runnable() {
                @Override
                public void run() {
                    if(callBackParm!=null)
                    {
                        LogUtil.d("Thread","4");
                        callBackParm.successful(list);
                        LogUtil.d("Thread","5");

                    }
                }
            });

        } catch (final Exception e) {
            e.printStackTrace();
            handler.post(new Runnable() {
                @Override
                public void run() {
                    if (callBackParm!=null)
                    {
                        LogUtil.d("Thread","7");
                        callBackParm.failed(e.getMessage());
                    }
                }
            });

        }
    }
    public interface CallBackParm
    {
        void successful(List<String>list);
        void failed(String e);
    }

}


